package fanjingzhu.check.action;

import javax.annotation.Resource;

import publics.model.Application;
import publics.model.Enterprise;
import publics.util.Page;

import com.opensymphony.xwork2.ActionSupport;

import fanjingzhu.check.service.ApplicationService;
import fanjingzhu.check.service.EnterpriseService;

public class LoanCheckAction extends ActionSupport  {

	private static final long serialVersionUID = 1L;
	ApplicationService applicationService;  //spring注入进来的 companyService
	EnterpriseService enterpriseService;

	
	private boolean success;   //此参数为必须的， extjs根据这个参数的值判断是否成功执行操作
	private int limit;  // 每页多少个记录
	private int start;   //分页查询的 要查询数据的开始号 ，和offset值相同
	private String conditions;//查询条件（即搜索页面上文本框中输入的值），多个条件用空格分开
	private Page page;   //这是分页查询用的辅助类，用此类可以解决分页查询中要返回多个参数的问题，推荐使用

	private Application application;
	private Integer applicationId;
	private Enterprise enterprise;
	private Integer enterpriseId;
	
	public ApplicationService getApplicationService() {
		return applicationService;
	}
	@Resource(name="applicationService")
	public void setApplicationService(ApplicationService applicationService) {
		this.applicationService = applicationService;
		System.out.println("ApplicationServiceImpl inject in LoanCheckAction!");
	}
	public EnterpriseService getEnterpriseService() {
		return enterpriseService;
	}
	@Resource(name="enterpriseService")
	public void seEnterpriseService(EnterpriseService enterpriseService) {
		this.enterpriseService = enterpriseService;
		System.out.println("EnterpriseServiceImpl inject in LoanCheckAction!");
	}
	/**
	 * 根据条件分页查找所有待初审的申请表
	 * @return
	 */
	public String findAllApplicationFirst() {  
		page = new Page();
		page.setStart(start);
		page.setLimit(limit = (limit == 0) ? 20 : limit);
		page = applicationService.findByPageFirst(page);  //查询 
//		page = enterpriseService.findByStatePage(page);
		if ((null != page.getRoot() && page.getTotalProperty() > 0 )||(null == page.getRoot() && page.getTotalProperty() == 0 )) {
			page.setSuccess(true);
			System.out.println("查询成功返回数据，准备返回。page.root="+page.getRoot());//测试用
		}else{
			success = false;
		}
		return SUCCESS;
	}
	
	/**
	 * 查找所有待复审的申请表
	 * @return
	 */
	public String findAllApplicationSecond() { 
		page = new Page();
		page.setStart(start);
		page.setLimit(limit = (limit == 0) ? 20 : limit);
		page = applicationService.findByPageSecond(page);  //查询 
//		page = enterpriseService.findByStatePage(page);
		if ((null != page.getRoot() && page.getTotalProperty() > 0 )||(null == page.getRoot() && page.getTotalProperty() == 0 )) {
			page.setSuccess(true);
			System.out.println("查询成功返回数据，准备返回。page.root="+page.getRoot());//测试用
		}else{
			success = false;
		}
		return SUCCESS;
	}
	
	/**
	 * 查找所有待终审的申请表
	 * @return
	 */
	public String findAllApplicationLast() {  
		page = new Page();
		page.setStart(start);
		page.setLimit(limit = (limit == 0) ? 20 : limit);
		page = applicationService.findByPageLast(page);  //查询 
//		page = enterpriseService.findByStatePage(page);
		if ((null != page.getRoot() && page.getTotalProperty() > 0 )||(null == page.getRoot() && page.getTotalProperty() == 0 )) {
			page.setSuccess(true);
			System.out.println("查询成功返回数据，准备返回。page.root="+page.getRoot());//测试用
		}else{
			success = false;
		}
		return SUCCESS;
	}
	/**
	 * 
	 * 根据企业id查找贷款申请
	 * @return
	 */
	public String findByEntId(){
		
		this.setEnterprise(enterpriseService.findById(enterpriseId));
		if (this.getEnterprise() != null) {
			success = true;
		}else{
			success = false;
		}
		System.out.println("已经查询到id号为"+enterpriseId+"的记录");
		return SUCCESS;
	}
	/**
	 * 根据id查找企业的相关信息表
	 * @return
	 */
    public String findPageByEntId() {  
  	    println("enter in findPageByEntId");
    	if (this.getEnterpriseId() != null) {
		page = new Page(); // 实例化分页对象
		page.setStart(start);
		page.setLimit(limit = (limit == 0) ? 20 : limit);
		page = enterpriseService.findByPageId(page,this.getEnterpriseId());  //查询指定id的企业的相关信息表 
//		page = enterpriseService.findByStatePage(page);
		if ((null != page.getRoot() && page.getTotalProperty() > 0 )||(null == page.getRoot() && page.getTotalProperty() == 0 )) {
			page.setSuccess(true);
			System.out.println("查询成功返回数据，准备返回。page.root="+page.getRoot());//测试用
		}else{
			success = false;
		}
    	}
		return SUCCESS;
	}
	
	public boolean isSuccess() {
		return success;
	}
	public int getLimit() {
		return limit;
	}
	public int getStart() {
		return start;
	}
	public String getConditions() {
		return conditions;
	}
	public Page getPage() {
		return page;
	}
	public Application getApplication() {
		return application;
	}
	public Integer getApplicationId() {
		return applicationId;
	}
	public Enterprise getEnterprise() {
		return enterprise;
	}
	public Integer getEnterpriseId() {
		return enterpriseId;
	}
	public void setSuccess(boolean success) {
		this.success = success;
	}
	public void setLimit(int limit) {
		this.limit = limit;
	}
	public void setStart(int start) {
		this.start = start;
	}
	public void setConditions(String conditions) {
		this.conditions = conditions;
	}
	public void setPage(Page page) {
		this.page = page;
	}
	public void setApplication(Application application) {
		this.application = application;
	}
	public void setApplicationId(Integer applicationId) {
		this.applicationId = applicationId;
	}
	public void setEnterpriseService(EnterpriseService enterpriseService) {
		this.enterpriseService = enterpriseService;
	}
	public void setEnterprise(Enterprise enterprise) {
		this.enterprise = enterprise;
	}
	public void setEnterpriseId(Integer enterpriseId) {
		this.enterpriseId = enterpriseId;
	}
}
